#pragma once
/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework Class Library
 * Version 2.00
 * 
 * DNS T-Signature Record Structure
 *      Represents a DNS signature (SIG) record.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
#include "stdafx.h"
using namespace System;
using namespace System::Net;

namespace Adaptive
{
	namespace Network
	{
		namespace Dns
		{
			/// <summary>
			/// Represents a DNS T-signature (TSIG) record.
			/// </summary>
			public value struct DnsTSignatureRecord
			{
			internal:
				/// <summary>
				/// Initializes a new instance of the class from the unmanaged record.
				/// </summary>
				/// <param name="record"> A pointer to a DNS_RECORD structure whose contents are to be copied.</param>
				DnsTSignatureRecord(DNS_RECORD* record)
				{
					if (record == NULL)
					{
						AlgorithmName = String::Empty;
						AlgorithmPacket = IntPtr::Zero;
						SignaturePointer = IntPtr::Zero;
						CreateTime = 0;
						FudgeTime = 0;
						OriginalXid = 0;
						Error = 0;
						SigLength = 0;  
						AlgorithmNameLength = 0;
					}
					else
					{
						AlgorithmName = gcnew String ( record->Data.TSIG.pNameAlgorithm );
						AlgorithmPacket = IntPtr::IntPtr(record->Data.TSIG.pAlgorithmPacket );
						SignaturePointer = IntPtr::IntPtr(record->Data.TSIG.pSignature);
						CreateTime = record->Data.TSIG.i64CreateTime;
						FudgeTime = record->Data.TSIG.wFudgeTime;
						OriginalXid = record->Data.TSIG.wOriginalXid;
						Error = record->Data.TSIG.wError;
						SigLength = record->Data.TSIG.wSigLength;
						AlgorithmNameLength = record->Data.TSIG.cAlgNameLength;
					}
				}
			private:
				/// <summary>
				/// Static constructor.
				/// </summary>
				static DnsTSignatureRecord()
				{
				}

			public:
				/// <summary>
				/// Name of the key used in the domain name syntax.
				/// </summary>
				/// <value>
				/// Algorithm name or empty string.
				/// </value>
				String^		AlgorithmName;
				/// <summary>
				/// Pointer to the packet containing the algorithm.
				/// </summary>
				/// <value>
				/// An <see cref="IntPtr"/> containing the pointer to the algorithm.
				/// </value>
				IntPtr		AlgorithmPacket;  
				/// <summary>
				/// Pointer to the signature data.
				/// </summary>
				/// <value>
				/// An <see cref="IntPtr"/> containing the pointer to the signature.
				/// </value>
				IntPtr		SignaturePointer;
				/// <summary>
				/// Time the key transaction authentication was created, expressed in seconds since the beginning of January 
				/// 1, 1970, Greenwich Mean Time (GMT), excluding leap seconds.
				/// </summary>
				/// <value>
				/// Creation time value in seconds.
				/// </value>
				__int64		CreateTime;  
				/// <summary>
				/// Time, in seconds, from which the <b>CreateTime</b> may be in error.
				/// </summary>
				/// <value>
				/// Additional time value in seconds to modify the <b>CreateTime</b> property with.
				/// </value>
				short		FudgeTime;  
				/// <summary>
				/// Original message identifier
				/// </summary>
				/// <value>
				/// Identifier value.
				/// </value>
				short		OriginalXid;  
				/// <summary>
				/// Error, expressed in expanded RCODE that covers TSIG processing. See Remarks for more information about the TSIG resource record.
				/// </summary>
				/// <value>
				/// RCODE value.
				/// </value>
				short		Error;  
				/// <summary>
				/// Length, in bytes, of the Signature member.
				/// </summary>
				/// <value>
				/// Size of the data in the signature.
				/// </value>
				short		SigLength;  
				/// <summary>
				/// Length, in bytes, of the <b>AlgorithmName</b> member.
				/// </summary>
				/// <value>
				/// Length, in bytes, of the <b>AlgorithmName</b> member.
				/// </value>
				Byte		AlgorithmNameLength;  
			};
		}
	}
}